import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Arrays;

public class MaJiangPaiTypeAll {


    static int total = 0;
    static BufferedWriter writer;

    static {
        try {
            File file = new File("/data/全部牌型列表（14张麻将）.txt");
            if (!file.exists()) {
                if (!file.getParentFile().exists())
                    file.getParentFile().mkdirs();
                file.createNewFile();
                writer = new BufferedWriter(new FileWriter(file));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] strs) throws IOException {
        long time = System.currentTimeMillis();
        digui(new int[27], 0, 14);
        writer.append("总计：" + total + "\n");
        writer.append("耗时：" + (System.currentTimeMillis() - time));
        writer.flush();
        writer.close();
    }

    public static void digui(int[] ints, int start, int end) throws IOException {
        if (Arrays.stream(ints).sum() == 14) {
            StringBuilder builder = new StringBuilder(27);
            for (int i = ints.length - 1; i >= 0; i--) {
                if (builder.length() == 0 && ints[i] == 0) continue;
                builder.insert(0, ints[i]);
            }
            writer.append(builder.append("\n"));
            total++;
            return;
        }
        for (int i = start; i < 27 - end + 1; i++) {
            //开头为0情况跳过
            if (i != 0 && ints[0] == 0) break;
            //连续为0的情况跳过
            if (i >= 2 && ints[i - 1] == 0 && ints[i - 2] == 0) break;
            int[] copy = Arrays.copyOf(ints, ints.length);
            copy[i]++;
            if (copy[i] == 4) {
                digui(copy, i + 1, end - 1);
            } else {
                digui(copy, i, end - 1);
            }
        }
    }

}
